import request from "@/utils/request";
import {
  SZ_ACCOUNT_HOST,
  COURSE_API_HOST,
  GKK_API_HOST
} from "@/plugins/config";

// 使用账号密码登录
export const loginByAccount = (data, { source, customApi } = {}) => {
  return request({
    url: `${customApi || SZ_ACCOUNT_HOST}/uc/login`,
    method: "post",
    params: { source },
    data,
    noticeMessage: false
  });
};

// 使用手机号登录
export const loginByPhone = (data, { customApi } = {}) => {
  return request({
    url: `${customApi || GKK_API_HOST}/login/cellphonelogin`,
    method: "get",
    params: data
  });
};

// 获取图片验证码
export const getImgCaptcha = ({ customApi } = {}) => {
  return request({
    url: `${customApi || COURSE_API_HOST}/captcha`,
    method: "get"
  });
};

// 手机登录--发送短信
export const sendLoginSms = (data, { customApi } = {}) => {
  return request({
    url: `${customApi || COURSE_API_HOST}/login/sendsms`,
    method: "post",
    data
  });
};

// 手机登录--验证code
export const checkLoginCaptcha = (data, { customApi } = {}) => {
  return request({
    url: `${customApi || COURSE_API_HOST}/login/checkcode`,
    method: "post",
    data
  });
};

// 开通资源库--发送短信
export const sendRegisterSms = (data, { customApi } = {}) => {
  return request({
    url: `${customApi || COURSE_API_HOST}/register/sendsms`,
    method: "post",
    data
  });
};

// 重置密码--发送短信
export const sendResetSms = (data, { customApi } = {}) => {
  return request({
    url: `${customApi || COURSE_API_HOST}/findpassword/sendsms`,
    method: "post",
    data
  });
};

// 重置密码--发送邮件
export const sendResetEmail = (data, { customApi } = {}) => {
  return request({
    url: `${customApi || COURSE_API_HOST}/findpassword/sendmail`,
    method: "post",
    data
  });
};

// 重置密码--验证手机验证码
export const checkCaptchaByPhone = (data, { customApi } = {}) => {
  return request({
    url: `${customApi || COURSE_API_HOST}/findpassword/verifycode`,
    method: "post",
    data
  });
};

// 重置密码--验证邮箱验证码
export const checkCaptchaByEmail = (data, { customApi } = {}) => {
  return request({
    url: `${customApi || COURSE_API_HOST}/findpassword/verifymailcode`,
    method: "post",
    data
  });
};

// 重置密码--保存信息
export const saveResetInfo = (data, { customApi } = {}) => {
  return request({
    url: `${customApi || COURSE_API_HOST}/findpassword/resetPassword`,
    method: "post",
    data
  });
};

// 登录
export const loginByToken = (params, { customApi } = {}) => {
  return request({
    url: `${customApi || SZ_ACCOUNT_HOST}/uc/login/token`,
    method: "get",
    params
  });
};
